<?php

/*
 * 
 * 
 *  This software has been made FREE by author for the interest of other developers. 
 *       I hope this will help you in coding faster and robust php code
 *             You can modify and redistribute it as you like.
 *               Your comments, suggestions and corrections 
 *                           will be highly 
 *                            APPRECIATED. 
 *                                       Author
 * @author :   Roshan Budhathoki (developer.roshan@gmail.com);
 * @URL    :   <http://www.roshanbudhathoki.com>
 * 
 */

class Application extends base {
	protected $_view;
	
	public function __construct() {
		$this->setView ();
	}
	public function run($view = '') {
		$this->setView ( $view );
		
		switch (Params::getParam ( 'action' )) {
			case 'load-form' :
				
				$id = Params::getParam ( 'id' );
				$category = Model_Mapper_Categories::newInstance ()->getByID ( $id );
				if ($category) {
					$root = $category->getRoot ();
					$args = array ();
					$args ['ad_type'] = '';
					$args ['field'] = '';
					$args ['script'] = '';
					
					if (file_exists ( plugin_path () . $root->getSlug () . DS . 'adtype.phtml' )) {
						$args ['ad_type'] = file_get_contents ( plugin_path () . $root->getSlug () . DS . 'adtype.phtml' );
					}
					if (file_exists ( plugin_path () . $root->getSlug () . DS . 'form.phtml' )) {
						$args ['field'] = file_get_contents ( plugin_path () . $root->getSlug () . DS . 'form.phtml' );
					}
					if (file_exists ( plugin_path () . $root->getSlug () . DS . 'script.phtml' )) {
						$args ['script'] = file_get_contents ( plugin_path () . $root->getSlug () . DS . 'script.phtml' );
					}
					
					echo json_encode ( $args );
				
				} else {
					echo '';
				}
				break;
		}
	}
}